package base_Suanfa.tanxin;

import java.util.Arrays;

public class tanxin_zuidashuliang {
    /*
    题目:轮船想装载最多数量的货物
    轮船在一堆货品中，装最多货物,分别为3,5,4,10,7,14,2,11
     */
    public static void main(String[] args) {
      int  weights[]={3,5,4,10,7,14,2,11};
        Arrays.sort(weights);
        int capacity=30,total=0,count=0;  //total用来记录目前的重量
        for(int i=0;i<weights.length;i++){
            int n=total+weights[i];
            if(n<=capacity){
                total=n;
                count++;
                System.out.println(weights[i]);
            }
            else
                break;
        }
        System.out.println("一共选了"+count);
    }
}
